// 路由权限
import router from "@/router";
import { useTokenStore } from "@/stores/token";
// 全局前置守卫,访问路由之前执行
router.beforeEach((to: any, from: any, next: any) => {
  // to你将要访问的
  // from你从哪个路由来
  // next路由放行函数
  const token = useTokenStore().token;
  if (token) {
    next();
  } else {
    if (
      to.path === "/login" ||
      to.path === "/register" ||
      to.path === "/teacherLogin"
    ) {
      next();
    } else {
      next({ path: "/login" });
    }
  }
});

// 全局后置守卫
router.afterEach((to: any, from: any, next: any) => {});
